import JSEncrypt from "jsencrypt";

//公私钥密码对生成  http://web.chacuo.net/netrsakeypair
const publicKey = `MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANxvzrFVf8F0ESBXez4Q/Rt3fAxyHBlrg43uL55rW6Va70aHS4qhUImOopiXyieD81e4E6CBHE34b1u2jq3La88CAwEAAQ==`;
const privateKey = `MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEA3G/OsVV/wXQRIFd7PhD9G3d8DHIcGWuDje4vnmtbpVrvRodLiqFQiY6imJfKJ4PzV7gToIEcTfhvW7aOrctrzwIDAQABAkB5In/k92UDO/MFYM165/8PDvP+Kt7CIVDjt9Y3Kivsiyy0GAebsRIcAck8YaCeCxLM3rqcGB66BQzKxIgNGmPxAiEA+cMKSLmBbJ9216SFPxDvMfSrws1VSulzYrI8RyVslqUCIQDh8UOxAHYaCz88OxfIPI5aFrx6fPhcpOihsmkZjvpiYwIhAPbXt5tGk85KEAdyFyrMTsrdmL/vdcOS1DIQG5jpONftAiEAmiIgb4tFBhdOGCSn4K2O3t5LzbObKnhFSqmPESR8oskCIQCKH3EG5n9iu+c9jE5IxX+LJww/JUVaKvIjWzJTqqwiJA==`;

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}